/**
 * @author Aaron
 * @createTime 9:53 2022/7/1
 **/
package db_main

import (
	"errors"
	"fmt"
	"gorm.io/gorm"
	"longmen/server/pkg/common/helper/util"
	"longmen/server/pkg/db/mysql"
	"longmen/server/pkg/db/mysql/models/models_main"
)

func GetHelpList() ([]*models_main.Help, error) {
	fName := "GetHelpList"
	o := make([]*models_main.Help, 0)
	err := mysql.GetRTable(&models_main.Help{}).Select("id,title,content,type,icon").Find(&o).Error
	if err != nil {
		err = fmt.Errorf("%s%s", util.Convert(fName), err.Error())
	}
	return o, err
}
func GetHelp(id uint) (*models_main.Help, error) {
	fName := "GetHelp"
	o := &models_main.Help{}
	table := mysql.GetRTable(&models_main.Help{}).Select("id,title,content,type,icon").Where("id=?", id)
	err := table.Take(&o).Error
	if errors.Is(err, gorm.ErrRecordNotFound) {
		err = nil
	}
	if err != nil {
		err = fmt.Errorf("%s%s", util.Convert(fName), err.Error())
	}
	return o, err
}
